<template>
  <div class="tabbar-item" @click="handleClick">
    <slot name="item-icon" v-if="!active"> </slot>
    <slot name="item-active-icon" v-else> </slot>
    <div :class="{ 'icon-color': active }">
      <slot name="item-text"> </slot>
    </div>
  </div>
</template>

<script>
import { useRouter, useRoute } from "vue-router";
import { computed } from "vue";
export default {
  props: {
    path: String,
  },
  setup(props) {
    const router = useRouter();
    const route = useRoute();
    const handleClick = () => {
      router.push(props.path);
    };

    const active = computed(() => {
      return route.path === props.path;
    });
    return {
      handleClick,
      active,
    };
  },
};
</script>

<style scoped>
.tabbar-item {
  flex: 1;
  text-align: center;
}
</style>